public class Test {
}

// Book.java
 class Book {
    // 成员变量
    private String title;
    private String author;
    private int yearPublished;
    private boolean isAvailable;

    // 构造方法
    public Book(String title, String author, int yearPublished) {
        this.title = title;
        this.author = author;
        this.yearPublished = yearPublished;
        this.isAvailable = true; // 默认图书是可借阅的
    }

    // Getter和Setter方法
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getYearPublished() {
        return yearPublished;
    }

    public void setYearPublished(int yearPublished) {
        this.yearPublished = yearPublished;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    // 借阅和归还方法
    public void borrow() {
        if (isAvailable) {
            isAvailable = false;
            System.out.println("《" + title + "》已被借出");
        } else {
            System.out.println("抱歉，《" + title + "》已被借出");
        }
    }

    public void returnBook() {
        if (!isAvailable) {
            isAvailable = true;
            System.out.println("《" + title + "》已归还");
        } else {
            System.out.println("错误：这本书已经在图书馆中");
        }
    }

    // 重写toString方法，用于打印书籍信息
    @Override
    public String toString() {
        return "《" + title + "》" +
                ", 作者: " + author +
                ", 出版年份: " + yearPublished +
                ", 状态: " + (isAvailable ? "可借阅" : "已借出");
    }

    // 主方法，程序入口点
    public static void main(String[] args) {
        // 创建两本书
        Book book1 = new Book("Java核心技术", "Cay S. Horstmann", 2024);
        Book book2 = new Book("Effective Java", "Joshua Bloch", 2022);

        // 打印书籍信息
        System.out.println(book1);
        System.out.println(book2);

        // 借阅书籍
        book1.borrow();
        book2.borrow();

        // 尝试再次借阅已借出的书籍
        book1.borrow();

        // 归还书籍
        book1.returnBook();

        // 再次尝试归还已归还的书籍
        book1.returnBook();

        // 再次打印书籍信息
        System.out.println("\n最新状态:");
        System.out.println(book1);
        System.out.println(book2);
    }
}
